<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
    </script>
    <input type="button" value="aaa">
    <input type="button" value="bbb">
    <input type="button" value="ccc">
    <script>
        let allinput = document.querySelectorAll('input')
        for (let i = 0; i < allinput.length; i++) {
            allinput[i].onclick = function() {
                alert(i);
            }
        };
    </script>
</body>

</html>